#include "render_system/basic_define.h"

#include <new>
#include "render_system/gl_header.h"
#include "arithmetic.h"


// static memeber initialize
const PixelFormat PixelFormat::PF_RGBA_8U(GL_RGBA8UI, GL_RGBA_INTEGER, 4, GL_UNSIGNED_BYTE, 4*sizeof(unsigned char));
const PixelFormat PixelFormat::PF_RGBA_32F(GL_RGBA32F, GL_RGBA, 4, GL_FLOAT, 4*sizeof(float));

const PixelFormat PixelFormat::PF_RGB_8U(GL_RGB8UI, GL_RGB_INTEGER, 3, GL_UNSIGNED_BYTE, 3*sizeof(unsigned char));
const PixelFormat PixelFormat::PF_RGB_32F(GL_RGB32F, GL_RGB, 3, GL_FLOAT, 3*sizeof(float));

const PixelFormat PixelFormat::PF_RG_8U(GL_RG8UI, GL_RG_INTEGER, 2, GL_UNSIGNED_BYTE, 2*sizeof(unsigned char));
const PixelFormat PixelFormat::PF_RG_32F(GL_RG32F, GL_RG, 2, GL_FLOAT, 2*sizeof(float));

const PixelFormat PixelFormat::PF_R_32U(GL_R32UI, GL_RED_INTEGER, 1, GL_UNSIGNED_INT, sizeof(unsigned int));
const PixelFormat PixelFormat::PF_R_32F(GL_R32F, GL_RED, 1, GL_FLOAT, sizeof(float));


PixelFormat::PixelFormat(
    const size_t internalFormat,
    const size_t sourceformat,
    const size_t ch,
    const size_t type,
    const size_t storage)

    : _GLinternalFormat(internalFormat)
    , _GLformat(sourceformat)
    , _channels(ch)
    , _GLstorageType(type)
    , _storageBytes(storage)
{
}


PixelFormat::PixelFormat()
    : _GLformat(GL_RGBA)
    , _GLstorageType(GL_UNSIGNED_BYTE)
    , _channels(4)
    , _storageBytes(4*sizeof(unsigned char))
{
}


PixelFormat::~PixelFormat()
{

}

PixelFormat::PixelFormat( const PixelFormat& lvalue )
{
    memcpy(this, &lvalue, sizeof(PixelFormat));
}


bool PixelFormat::operator == ( const PixelFormat& lvalue ) const
{
    return _GLformat == lvalue._GLformat;
}


PixelFormat& PixelFormat::operator = ( const PixelFormat& lvalue )
{
    return *new(this) PixelFormat(lvalue);
}


size_t PixelFormat::glInternalFormat() const
{
    return _GLinternalFormat;
}


size_t PixelFormat::glFormat() const
{
    return _GLformat;
}


size_t PixelFormat::channels() const
{
    return _channels;
}


size_t PixelFormat::glStorageType() const
{
    return _GLstorageType;
}


size_t PixelFormat::bytes() const
{
    return _storageBytes;
}
